# -*- coding:utf-8 -*-

from rest_framework.viewsets import ModelViewSet

from Apps.Interface.filters.interfaceCatFilter import InterfaceCatFilter
from Apps.Interface.models import InterfaceCat
from Apps.Interface.ser.interfaceCat import InterfaceCatSer
from Apps.common.response import SuccessResponse
from Apps.util.get_tree import get_tree
import logging

logger = logging.getLogger("django")


# Create your views here.

class InterfaceCatView(ModelViewSet):
    queryset = InterfaceCat.objects.all()
    serializer_class = InterfaceCatSer
    filter_class = InterfaceCatFilter
    authentication_classes = []

    def list(self, request, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())
        serializer = self.get_serializer(queryset, many=True)

        # 获取所有的模块项
        source_list = [dict(item) for item in serializer.data]

        return SuccessResponse(get_tree(source_list))

